<template>
  <!-- 申请修改dialog -->
  <el-dialog
    title="申请修改"
    v-model="visible"
    width="30%"
    destroy-on-close
    @closed="$emit('closed')"
  >
    <el-form
      :model="form"
      ref="dialogForm"
      label-width="80px"
      label-position="right"
      class="noFlex"
    >
      <el-form-item label="标题">
        <el-input
          v-model="form.title"
          clearable
          placeholder="请输入标题"
        ></el-input>
      </el-form-item>
      <el-form-item label="描述">
        <el-input
          v-model="form.opinion"
          clearable
          type="textarea"
          rows="5"
          placeholder="请输入申请描述内容"
        ></el-input>
      </el-form-item>
    </el-form>
    <template #footer>
      <el-button @click="visible = false">取 消</el-button>
      <el-button type="primary" :loading="isSaveing" @click="submit()"
        >确 定</el-button
      >
    </template>
  </el-dialog>
</template>

<script>
export default {
  emits: ['success', 'closed'],
  data () {
    return {
      form: {
        correlationId: '',//关联主表id
        applicantId: '',//申请人id
        departmentId: '',
        title: '',
        opinion: '',
        streamType: '',//流程类型
      },
      visible: false,
      isSaveing: false,

    }
  },
  props: {
    // checkApi: { type: Object, default: () => { } },
  },
  mounted () {

  },
  methods: {
    //显示
    open (data, type) {
      console.log(data)
      this.visible = true
      this.form.correlationId = data.id
      let userInfo = this.$TOOL.data.get('USER_INFO')
      this.form.applicantId = userInfo.userId
      this.form.departmentId = userInfo.departmentId
      this.form.title = `【${data.customerName ? data.customerName : data.name}】的申请修改`
      this.form.streamType = type
    },
    submit () {
      this.$refs.dialogForm.validate(async (valid) => {
        if (valid) {
          this.isSaveing = true
          let res = await this.$API.workflow.handleApply.post(this.form)
          this.isSaveing = false
          if (res.code == 200) {
            this.visible = false
            this.$emit('success')
            this.$message.success("操作成功")
          }
        }
      })
    },

  }
}
</script>

<style lang='scss' scoped>
</style>
